import React, { PureComponent } from "react";
import { connect } from "react-redux";
import Loading from "components/Loading";
import TabBar from "components/TabBar";
import { getUser } from "actions/user";
import { Login } from "actions/login";
import { isOverflow } from "app/utils";

import PropTypes from 'prop-types';
import "assets/scss/fonts.scss";
import "assets/scss/antd.scss";
import "assets/scss/app.scss";
import Drawer from 'components/Drawer'



@connect(
  state => ({
    user: state.user,
    config: state.config,
    common:state.common,
    login:state.login
  }),
  {
    getUser,
    Login
  }
)
export default class extends PureComponent {
  componentDidMount() {
    const { getUser,Login } = this.props;
    // getUser();
    const {router} = this.context
    // setTimeout(()=>{
    //   router.push({
    //     pathname: '/invite'
    //   })
    // },3000)
    // console.log(router.location.query)
    if(localStorage.getItem('isLogin')=='true'){
      Login(true)
      isOverflow(false);
    }
  }

  static contextTypes = {
    router: PropTypes.object.isRequired
  }
  render() {
    const { children ,history} = this.props;
    
    let config = {
      navs: [
        { link: "/", icon: "i-about", title: "首页", key: 1 },
        { link: "/projectList", icon: "i-buying", title: "列表", key: 2 },
        { link: "/game", icon: "i-buying", title: "摇一摇", key: 3 },
        { link: "/invite", icon: "i-camera", title: "分享", key: 4 },
        { link: "/my", icon: "i-check", title: "我的", key: 5 }
      ]
    };
    let hash = location.hash.substring(1,location.hash.length)
    let {isHide} = this.props.common
    let str
    
    config.navs.find((n)=>{
      let link = n.link
      if((link == (hash)||link+'?flag=1' == (hash)||link+'?flag=2' == (hash))&&link != '/game'){
       str =  <TabBar navs={config.navs}/>
      }
      // n.link == (hash)&&hash!='/game' && <TabBar navs={config.navs}/>
    })
      console.log(children.key,'----children')
    return (
      <div>
        <Drawer isHide={isHide}  key="a"/>
       {children}
        {/* <TabBar navs={config.navs} /> */}
        {/* {config.navs.find((n) => n.link == (hash)&&hash!='/game') && <TabBar navs={config.navs}/>} */}
        {str}
      </div>
    );
  }
}
